package com.local.localRestful.Controller;

import com.local.localRestful.domain.User;
import com.local.localRestful.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by zzy on 2018/1/14.
 */
@RestController
public class UserController {

    private  final UserRepository userRepository;

    @Autowired
    public  UserController(UserRepository userRepository){
        this.userRepository=userRepository;
    }

    @PostMapping(value = "/person/save"/*,produces = "text/html;charset=UTF-8"*/)
    public User save(@RequestParam("name") String name){
        User user=new User();
        user.setName(name);
        if(userRepository.save(user)){
         System.out.println("保存成功"+user.toString());
        }else{
            System.out.println("失败");
        }
        return user;
    }
}
